package com.petecat.interchan;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @ClassName:  Swagger2   
 * @Description:swagger配置
 * @author: mhuang
 * @date:   2017年7月18日 下午9:21:57
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

	@Bean
    public Docket createRestApi() {
		ParameterBuilder tokenPar = new ParameterBuilder();  
    	List<Parameter> pars = new ArrayList<>();  
    	tokenPar.name("Authorization").description("Bearer 开头加上登录的时候令牌,填写时表示带用户凭证进行访问").modelRef(new ModelRef("string")).parameterType("header").required(false).build();  
        pars.add(tokenPar.build());
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.petecat.interchan"))
                .paths(PathSelectors.any()).build()
                .globalOperationParameters(pars);
    }

    private ApiInfo apiInfo() {
    	 return new ApiInfoBuilder()
                 .title("用户API")
                 .description("用户API编写")
                 .contact("皮特猫信息科技有限公司")
                 .version("1.0")
                 .build();
    }
}
